package com.dongdong.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdong.domain.Result;
import com.dongdong.em.ResultEnum;
import com.dongdong.pojo.TbSeller;
import com.dongdong.service.TbSellerService;
import com.dongdong.utils.ShiroUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("toRegister")
public class ShiroRegisterController {
    @Reference
    private TbSellerService tbSellerService;

    @RequestMapping("register")
    public String register(){
        return "admin/register";
    }


    @RequestMapping("getRegister")
    @ResponseBody
    public Result getRegister(TbSeller tbSeller) {
        TbSeller tbSeller1 = tbSellerService.getInfoLogin(tbSeller.getSellerId());

        if (tbSeller1 != null) {
           return Result.buildResult(ResultEnum.ERROR);
        }


        String password = tbSeller.getPassword();
        String s = ShiroUtils.generateSalt(5);
        String pwd = ShiroUtils.encryptPassword("MD5", password, s, 3);
        tbSeller.setPassword(pwd);
        tbSeller.setSalt(s);
        tbSellerService.insert(tbSeller);
       return Result.buildResult(ResultEnum.SUCCESS);
    }


}
